﻿<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Sub DDLTipoOraFt_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        '       imposta valore di default
        sender.items.FindByText("STD001 Standard").selected = True
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Not Page.IsPostBack Then
            Dim currentDate As String = DateTime.Now.ToString("dd/MM/yyyy")
            TB_Datada.Text = currentDate
        End If
        Dim sWhere As String = ""
        
        If Session("userLevel") = "" Then
            Session("userLevel") = "4"
        End If
        
        '	Authorization level 3 needed for this function
        If Int32.Parse(Session("userLevel")) < 4 Then
            Response.Redirect("/timereport/menu.aspx?msgtype=E&msgno=" & ConfigurationSettings.AppSettings("MSGNO_AUTHORIZATION_FAILED"))
        End If
        
        If DDL_Persona_Sel.SelectedValue <> "all" Or _
          (Session("DDL_Persona_Sel") <> Nothing And Not IsPostBack) Then
            sWhere = IIf(sWhere = "", " WHERE Hours.Persons_id = (@DDL_Persona_Sel)", sWhere & " AND Hours.Persons_id = (@DDL_Persona_Sel)")
        End If

        If DDL_Progetti_Sel.SelectedValue <> "all" Or _
            (Session("DDL_Progetti_Sel") <> Nothing And Not IsPostBack) Then
            sWhere = IIf(sWhere = "", " WHERE Hours.Projects_id = (@DDL_Progetti_Sel)", sWhere & " AND Hours.Projects_id = (@DDL_Progetti_Sel)")
        End If
        
        If TB_Datada.Text <> Nothing Or _
            (Session("TB_Datada") <> Nothing And Not IsPostBack) Then
            sWhere = IIf(sWhere = "", " WHERE Hours.Date >= (@TB_Datada)", sWhere & " AND Hours.Date >= (@TB_Datada)")
        End If
        
        If TB_DataA.Text <> Nothing Or _
            (Session("TB_DataA") <> Nothing And Not IsPostBack) Then
            sWhere = IIf(sWhere = "", " WHERE Hours.Date <= (@TB_DataA)", sWhere & " AND Hours.Date <= (@TB_DataA)")
        End If
        
        DShours.SelectCommand = "SELECT Hours.Hours_Id, Hours.Projects_Id, Hours.Persons_id, Hours.Date, Hours.Hours, Hours.AccountingDate, Hours.CancelFlag, Hours.TransferFlag, Hours.Comment, Persons.Name AS NomePersona, Projects.ProjectCode + ' ' + Projects.Name AS NomeProgetto FROM Hours INNER JOIN Projects ON Hours.Projects_Id = Projects.Projects_Id INNER JOIN Persons ON Hours.Persons_id = Persons.Persons_id" _
                                 & sWhere & " ORDER BY Hours.Date, Hours.Projects_ID, Hours.Persons_Id"
        
    End Sub

    Protected Sub GV_Ore_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs)

        ' Insert data if the CommandName == "Insert" 
        ' and the validation controls indicate valid data... 
        If e.CommandName = "Insert" AndAlso Page.IsValid Then
       
            ' Programmatically reference Web controls in the inserting interface... 
            Dim NewProjectsId As DropDownList = GV_Ore.FooterRow.FindControl("DDLProjects_Id")
            Dim NewPersonaId As DropDownList = GV_Ore.FooterRow.FindControl("DDL_Persona")
            Dim NewData As TextBox = GV_Ore.FooterRow.FindControl("TB_Data")
            Dim NewOre As TextBox = GV_Ore.FooterRow.FindControl("TB_Ore")
            Dim NewAccountingDate As TextBox = GV_Ore.FooterRow.FindControl("TB_AccountingDate")
            Dim NewStorno As CheckBox = GV_Ore.FooterRow.FindControl("CB_Storno")
            Dim NewTrasferta As CheckBox = GV_Ore.FooterRow.FindControl("CB_Trasferta")

            DShours.InsertParameters("Projects_Id").DefaultValue = NewProjectsId.SelectedValue            
            DShours.InsertParameters("Persons_id").DefaultValue = NewPersonaId.SelectedValue
            DShours.InsertParameters("Date").DefaultValue = NewData.Text
            DShours.InsertParameters("Hours").DefaultValue = NewOre.Text
            DShours.InsertParameters("AccountingDate").DefaultValue = NewAccountingDate.Text
            DShours.InsertParameters("CancelFlag").DefaultValue = NewStorno.Checked
            DShours.InsertParameters("TransferFlag").DefaultValue = NewTrasferta.Checked
            DShours.InsertParameters("HourType_Id").DefaultValue = 1 ' valore di default

            ' Log
            DShours.InsertParameters("CreatedBy").DefaultValue = Session("persons_id")
            DShours.InsertParameters("CreationDate").DefaultValue = DateTime.Now()
            
            DShours.Insert()
            
        End If

    End Sub
        
    Protected Sub DDL_Persona_Sel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("DDL_Persona_Sel") = IIf(sender.selectedValue <> "all", sender.selectedValue, Nothing)
    End Sub

    Protected Sub DDL_Persona_Sel_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Resetta indice di selezione sulle dropdwonlist per non perderlo a seguito passaggio a pagina di dettaglio
        If Not IsPostBack And Session("DDL_Persona_Sel") <> Nothing Then
            DDL_Persona_Sel.SelectedValue = Session("DDL_Persona_Sel")
        End If
    End Sub

    Protected Sub DDL_Progetti_Sel_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("DDL_Progetti_Sel") = IIf(sender.selectedValue <> "all", sender.selectedValue, Nothing)
    End Sub

    Protected Sub DDL_Progetti_Sel_DataBound(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Resetta indice di selezione sulle dropdwonlist per non perderlo a seguito passaggio a pagina di dettaglio
        If Not IsPostBack And Session("DDL_Progetti_Sel") <> Nothing Then
            DDL_Progetti_Sel.SelectedValue = Session("DDL_Progetti_Sel")
        End If
    End Sub

    Protected Sub TB_Datada_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("TB_DataDa") = sender.text
    End Sub
    
    Protected Sub TB_Datada_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Resetta indice di selezione sulle dropdwonlist per non perderlo a seguito passaggio a pagina di dettaglio
        If Not IsPostBack And Session("TB_DataDa") <> Nothing Then
            TB_Datada.Text = Session("TB_DataDa")
        End If
    End Sub
    
    Protected Sub TB_DataA_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Resetta indice di selezione sulle dropdwonlist per non perderlo a seguito passaggio a pagina di dettaglio
        If Not IsPostBack And Session("TB_DataA") <> Nothing Then
            TB_DataA.Text = Session("TB_DataA")
        End If
    End Sub

    Protected Sub TB_DataA_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Session("TB_DataA") = sender.text
    End Sub

    Protected Sub DShours_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs)
        ' Audit    
        e.Command.Parameters("@LastModifiedBy").Value = Session("persons_id")
        e.Command.Parameters("@LastModificationDate").Value = DateTime.Now()
    End Sub
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Lista progetti</title>
    
    <link href="/timereport/include/commoncss.aspx" rel="stylesheet" type="text/css" />
    
    </head>

 <!-- Jquery per date picker  -->
  <link rel="stylesheet" href="/timereport/include/jquery/jquery-ui-1.10.3.custom.min.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script type="text/javascript" src="/timereport/include/jquery/jquery.ui.datepicker-it.js"></script>
  <script src="/timereport/include/jquery/jquery-ui-1.10.3.custom.min.js"></script>    
  <script>$(function () { $('.datepickclass').datepicker($.datepicker.regional['it']); }); </script>
<!-- FINE Jquery per date picker  -->

<script language=JavaScript src= "/timereport/include/menu/menu_array.js" type=text/javascript></script>
<script language=JavaScript src= "/timereport/include/menu/mmenu.js" type=text/javascript></script>   

</head>
<body>

<table width="760" border="0"> 
 <tr> 
    <td height="30" class="BarraTop" align="right">Utente: <%= session("UserName") %> 
    </td>
</table> 

    <form id="form1" runat="server">
<table width="760" border="0" class="GridTab"> 
  </tr>
  <td>Persona:</td>
  <td>
      <asp:DropDownList ID="DDL_Persona_Sel" runat="server" 
          AppendDataBoundItems="True" AutoPostBack="True" CssClass="TabellaLista" 
          DataSourceID="DDSPersone" DataTextField="Name" DataValueField="Persons_id" OnSelectedIndexChanged="DDL_Persona_Sel_SelectedIndexChanged" OnDataBound="DDL_Persona_Sel_DataBound">
                <asp:ListItem Text="Tutti i valori" Value="all" />
      </asp:DropDownList>
                </td>
    <td>Progetto:</td>
      <td>
          <asp:DropDownList ID="DDL_Progetti_Sel" runat="server" 
              AppendDataBoundItems="True" AutoPostBack="True" CssClass="TabellaLista" 
              DataSourceID="dsProjects" DataTextField="codice" DataValueField="Projects_Id" OnSelectedIndexChanged="DDL_Progetti_Sel_SelectedIndexChanged" OnDataBound="DDL_Progetti_Sel_DataBound">
                <asp:ListItem Text="Tutti i valori" Value="all" />
          </asp:DropDownList>
    </td>
  </tr>   
    <tr>
  <td>Data da:</td>
  <td>
            <asp:TextBox ID="TB_Datada" runat="server" Columns="10" MaxLength="10" OnTextChanged="TB_Datada_TextChanged" OnLoad="TB_Datada_Load" />
            <asp:RangeValidator ID="RV_DataDa" runat="server" Display="Dynamic" 
                ErrorMessage="Inserire un valore valido" MaximumValue="31/12/9999" 
                MinimumValue="01/01/2000" Type="Date" ValidationGroup="input" 
                ControlToValidate="TB_Datada">*</asp:RangeValidator>
            </td>
    <td>Data a:</td>
      <td>
            <asp:TextBox ID="TB_DataA" runat="server" Columns="10" MaxLength="10" 
              OnLoad="TB_DataA_Load" OnTextChanged="TB_DataA_TextChanged"></asp:TextBox>
            <asp:RangeValidator ID="RV_DataA" runat="server" Display="Dynamic" 
                ErrorMessage="Inserire un valore valido" MaximumValue="31/12/9999" 
                MinimumValue="01/01/2000" Type="Date" ValidationGroup="input" 
                ControlToValidate="TB_DataA">*</asp:RangeValidator>
            &nbsp;
            <asp:Button ID="BT_filtra" runat="server" Text="filtra" 
                ValidationGroup="input" />
            </td>
  </tr>   
</table> 
   
    <asp:GridView ID="GV_Ore" runat="server" AllowPaging="True"  CssClass="GridView" 
        AllowSorting="True" AutoGenerateColumns="False" 
        DataKeyNames="Hours_Id" PageSize="20" ShowFooter="True" 
        OnRowCommand="GV_Ore_RowCommand" DataSourceID="DShours" GridLines="None">
        <FooterStyle CssClass="GV_footer" />
        <RowStyle CssClass="GV_row" />
        <Columns>
            <asp:TemplateField HeaderText="Data" SortExpression="Date">
                <EditItemTemplate>
                    <asp:TextBox ID="TB_Data" runat="server" Columns="10" CssClass="TabellaLista" 
                        MaxLength="10" Text='<%# Bind("Date", "{0:d}") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="TB_Data" Display="None" 
                        ErrorMessage="Necessario specificare una data">*</asp:RequiredFieldValidator>
                    <asp:RangeValidator ID="RangeValidator1" runat="server" 
                        ControlToValidate="TB_Data" Display="None" 
                        ErrorMessage="Inserire una data valida" MaximumValue="31/12/9999" 
                        MinimumValue="01/01/2000" Type="Date"></asp:RangeValidator>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="TB_Data" runat="server" Columns="8" class = "datepickclass" MaxLength="10" Text='<%# Bind("Date", "{0:d}") %>' 
                        ></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                        ControlToValidate="TB_Data" Display="None" 
                        ErrorMessage="Necessario specificare una data" ValidationGroup="Insert">*</asp:RequiredFieldValidator>
                  &nbsp; <asp:RangeValidator ID="RangeValidator1" runat="server" 
                        ControlToValidate="TB_Data" Display="None" 
                        ErrorMessage="Inserire una data valida" MaximumValue="31/12/9999" 
                        MinimumValue="01/01/2000" Type="Date" ValidationGroup="Insert"></asp:RangeValidator>
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Date", "{0:d}") %>'></asp:Label>
                </ItemTemplate>
                <FooterStyle Wrap="False" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Progetto" SortExpression="Projects_Id">
                <EditItemTemplate>
                    <asp:DropDownList ID="DDLProjects_Id" runat="server" DataSourceID="dsProjects" 
                        DataTextField="codice" DataValueField="Projects_Id" 
                        SelectedValue='<%# Bind("Projects_Id") %>' Width="160px" 
                        CssClass="TabellaLista">
                    </asp:DropDownList>
                </EditItemTemplate>
                <AlternatingItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" BorderWidth="0px" 
                        CssClass=" GV_row_alt" Height="18px" ReadOnly="True" 
                        Text='<%# bind("NomeProgetto") %>'></asp:TextBox>
                </AlternatingItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="DDLProjects_Id" runat="server" 
                        AppendDataBoundItems="True" CssClass="TabellaLista" DataSourceID="dsProjects" 
                        DataTextField="codice" DataValueField="Projects_Id" 
                        SelectedValue='<%# Bind("Projects_Id") %>' Width="160px">
                        <asp:ListItem  Value="" Text="Selezionare un valore"/>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                        ControlToValidate="DDLProjects_Id" Display="None" 
                        ErrorMessage="Specificare un codice progetto" ValidationGroup="Insert">*</asp:RequiredFieldValidator>
                </FooterTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" Text='<%# bind("NomeProgetto") %>' 
                        BorderWidth="0px" CssClass=" GV_row" ReadOnly="True"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Persona" SortExpression="Persons_id">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" CssClass="TabellaLista" 
                        DataSourceID="DDSPersone" DataTextField="Name" DataValueField="Persons_id" 
                        SelectedValue='<%# Bind("Persons_id") %>' Width="130px">
                    </asp:DropDownList>
                </EditItemTemplate>
                <AlternatingItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" CssClass="GV_row_alt" ReadOnly="True" 
                        Text='<%# bind("NomePersona") %>'></asp:TextBox>
                </AlternatingItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="DDL_Persona" runat="server" AppendDataBoundItems="True" 
                        CssClass="TabellaLista" DataSourceID="DDSPersone" DataTextField="Name" 
                        DataValueField="Persons_id" 
                        SelectedValue='<%# Bind("Persons_id") %>' Width="130px">
                        <asp:ListItem  Value="" Text="Selezionare un valore"/>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                        ControlToValidate="DDL_Persona" Display="None" 
                        ErrorMessage="Specificare una persona di carico ore" ValidationGroup="Insert">*</asp:RequiredFieldValidator>
                </FooterTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox5" runat="server" CssClass="GV_row" 
                        ReadOnly="True" Text='<%# bind("NomePersona") %>'></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Ore" SortExpression="Hours">
                <EditItemTemplate>
                    <asp:TextBox ID="TB_Ore" runat="server" Columns="6" CssClass="TabellaLista" 
                        MaxLength="6" Text='<%# Bind("Hours", "{0:N}") %>'></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="TB_Ore" Display="None" 
                        ErrorMessage="Necessario specificare un valore per le ore">*</asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 
                        ControlToValidate="TB_Ore" Display="None" 
                        ErrorMessage="Inserire un valore numerico" 
                        ValidationExpression="(^\d*\,?\d*[1-9]+\d*$)|(^[1-9]+\d*\,\d*$)"></asp:RegularExpressionValidator>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="TB_Ore" runat="server" Columns="6" CssClass="TabellaLista" 
                        MaxLength="6" Text='<%# Bind("Hours", "{0:N}") %>' CausesValidation="True"></asp:TextBox>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                        ControlToValidate="TB_Ore" Display="None" 
                        ErrorMessage="Necessario specificare un valore" ValidationGroup="Insert">*</asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                        ControlToValidate="TB_Ore" Display="None" 
                        ErrorMessage="Inserire un valore numerico" 
                        ValidationExpression="(^\d*\,?\d*[1-9]+\d*$)|(^[1-9]+\d*\,\d*$)" 
                        ValidationGroup="Insert"></asp:RegularExpressionValidator>
                </FooterTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Hours", "{0:N}") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Competenza" SortExpression="AccountingDate">
                <EditItemTemplate>
                    <asp:TextBox ID="TB_AccountingDate" runat="server" 
                        class = "datepickclass" Columns="8" MaxLength="10" 
                        Text='<%# Bind("AccountingDate", "{0:d}") %>' >
                    </asp:TextBox>
                    <asp:RangeValidator ID="TB_AccountingDate_RV" runat="server" 
                    ControlToValidate="TB_AccountingDate" Display="None" 
                    ErrorMessage="Inserire una data competenza valida" MaximumValue="31/12/9999" 
                    MinimumValue="01/01/2000" Type="Date" ></asp:RangeValidator>
                </EditItemTemplate>
                <AlternatingItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server" CssClass="GV_row_alt" ReadOnly="True" 
                        Text='<%# bind("AccountingDate", "{0:d}") %>'></asp:TextBox>
                </AlternatingItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="TB_AccountingDate" runat="server" 
                        class = "datepickclass" Columns="8" MaxLength="10"
                        Text='<%# Bind("AccountingDate", "{0:d}") %>'  >
                    </asp:TextBox>
                    <asp:RangeValidator ID="TB_AccountingDate_RV" runat="server" 
                    ControlToValidate="TB_AccountingDate" Display="None" 
                    ErrorMessage="Inserire una data competenza valida" MaximumValue="31/12/9999" 
                    MinimumValue="01/01/2000" Type="Date" ValidationGroup="Insert"></asp:RangeValidator>
                </FooterTemplate>
                <ItemTemplate>
                    <asp:TextBox ID="TextBox6" runat="server"  CssClass="GV_row" 
                        ReadOnly="True" Text='<%# bind("AccountingDate", "{0:d}") %>'></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ST" SortExpression="CancelFlag">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" 
                        Checked='<%# Bind("CancelFlag") %>' />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:CheckBox ID="CB_Storno" runat="server" 
                        Checked='<%# Bind("CancelFlag") %>' />
                </FooterTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("CancelFlag") %>' 
                        Enabled="false" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="TR" SortExpression="TransferFlag">
                <EditItemTemplate>
                    <asp:CheckBox ID="CheckBox2" runat="server" 
                        Checked='<%# Bind("TransferFlag") %>' />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:CheckBox ID="CB_Trasferta" runat="server" 
                        Checked='<%# Bind("TransferFlag") %>' />
                </FooterTemplate>
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBox2" runat="server" Checked='<%# Bind("TransferFlag") %>' 
                        Enabled="false" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Nota" SortExpression="Comment">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Columns="15" CssClass="TabellaLista" 
                        Rows="3" Text='<%# Bind("Comment") %>' TextMode="MultiLine"></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Comment") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField ShowHeader="False">
                <EditItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="True" 
                        CommandName="Update" ImageUrl="/timereport/images/icons/16x16/S_F_OKAY.gif" 
                        Text="Update" />
                    &nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        CommandName="Cancel" ImageUrl="/timereport/images/icons/16x16/S_F_CANC.GIF" 
                        Text="Cancel" />
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:Button ID="Insert" runat="server" CommandName="Insert" Text="Insert" 
                        ValidationGroup="Insert" />
                </FooterTemplate>
                <ItemTemplate>
                    <asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False" 
                        CommandName="Edit" ImageUrl="/timereport/images/icons/16x16/modifica.gif" 
                        Text="Edit" />
                    &nbsp;<asp:ImageButton ID="ImageButton2" runat="server" CausesValidation="False" 
                        OnClientClick="return confirm('Il record verrà cancellato, confermi?');"
                        CommandName="Delete" ImageUrl="/timereport/images/icons/16x16/trash.gif" 
                        Text="Delete" />
                </ItemTemplate>
                <ItemStyle Wrap="False" />
            </asp:TemplateField>
        </Columns>
        <PagerStyle CssClass="GV_footer" />
        <HeaderStyle CssClass="GV_header" />
        <AlternatingRowStyle CssClass="GV_row_alt " />
    </asp:GridView>
    <asp:SqlDataSource ID="DShours" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
        SelectCommand="SELECT Hours.Hours_Id, Hours.Projects_Id, Hours.Persons_id, Hours.Date, Hours.Hours, Hours.AccountingDate, Hours.CancelFlag, Hours.TransferFlag, Hours.Comment, Persons.Name AS NomePersona, Projects.ProjectCode + ' ' + Projects.Name AS NomeProgetto FROM Hours INNER JOIN Projects ON Hours.Projects_Id = Projects.Projects_Id INNER JOIN Persons ON Hours.Persons_id = Persons.Persons_id ORDER BY Hours.Date, Hours.Projects_Id, Hours.Persons_id"  
        DeleteCommand="DELETE FROM [Hours] WHERE [Hours_Id] = @Hours_Id" 
        InsertCommand="INSERT INTO [Hours] ([Projects_Id], [Persons_id], [Date], [Hours], [HourType_Id], [AccountingDate], [CancelFlag], [TransferFlag], [Comment], [CreatedBy], [CreationDate]) VALUES (@Projects_Id, @Persons_id, @Date, @Hours, @HourType_Id, @AccountingDate, @CancelFlag, @TransferFlag, @Comment, @CreatedBy, @CreationDate)"                         
        UpdateCommand="UPDATE [Hours] SET [Projects_Id] = @Projects_Id, [Persons_id] = @Persons_id, [Date] = @Date, [Hours] = @Hours, [AccountingDate] = @AccountingDate, [CancelFlag] = @CancelFlag, [TransferFlag] = @TransferFlag, [Comment] = @Comment, [LastModifiedBy] = @LastModifiedBy, [LastModificationDate] = @LastModificationDate WHERE [Hours_Id] = @Hours_Id" 
        onupdating="DShours_Updating">
        <SelectParameters>
              <asp:ControlParameter ControlID="DDL_Persona_Sel" Name="DDL_Persona_Sel" 
                    PropertyName="SelectedValue" DefaultValue="%" />                                        
              <asp:ControlParameter ControlID="DDL_Progetti_Sel" Name="DDL_Progetti_Sel" 
                    PropertyName="SelectedValue" DefaultValue="%" />                                        
              <asp:ControlParameter ControlID="TB_DataDa" Name="TB_DataDa" 
                    PropertyName="text" Type="datetime" DefaultValue="1/1/2008" />                                        
              <asp:ControlParameter ControlID="TB_DataA" Name="TB_DataA" 
                    PropertyName="text" Type="datetime" DefaultValue="31/12/9999" />                                        
        </SelectParameters>
        <DeleteParameters>
            <asp:Parameter Name="Hours_Id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="Projects_Id" Type="Int32" />
            <asp:Parameter Name="Persons_id" Type="Int32" />
            <asp:Parameter Name="Date" Type="DateTime" />
            <asp:Parameter Name="Hours" Type="Decimal" />
            <asp:Parameter Name="AccountingDate" Type="DateTime" />
            <asp:Parameter Name="CancelFlag" Type="Boolean" />
            <asp:Parameter Name="TransferFlag" Type="Boolean" />
            <asp:Parameter Name="Comment" Type="String" />
            <asp:Parameter Name="Hours_Id" Type="Int32" />
            <asp:Parameter Name="LastModifiedBy" Type="Int32" />
            <asp:Parameter Name="LastModificationDate" Type="DateTime" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="Projects_Id" Type="Int32" />
            <asp:Parameter Name="Persons_id" Type="Int32" />
             <asp:Parameter Name="HourType_Id" Type="Int32" />            
            <asp:Parameter Name="Date" Type="DateTime" />
            <asp:Parameter Name="Hours" Type="Decimal" />
            <asp:Parameter Name="AccountingDate" Type="DateTime" />
            <asp:Parameter Name="CancelFlag" Type="Boolean" />
            <asp:Parameter Name="TransferFlag" Type="Boolean" />
            <asp:Parameter Name="Comment" Type="String" />
            <asp:Parameter Name="CreatedBy" Type="Int32" />
            <asp:Parameter Name="CreationDate" Type="DateTime" />

        </InsertParameters>
    </asp:SqlDataSource>
   
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" 
        ShowMessageBox="True" ShowSummary="False" />
   
        <asp:SqlDataSource ID="dsProjects" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
            
        
    SelectCommand="SELECT Projects_Id, ProjectCode + ' ' + Name AS codice, Active FROM Projects WHERE (Active = 1) ORDER BY codice" 
    EnableCaching="True">
        </asp:SqlDataSource>
   
    <asp:SqlDataSource ID="DDSPersone" runat="server" 
        ConnectionString="<%$ ConnectionStrings:MSSql12155ConnectionString %>" 
        
        
    SelectCommand="SELECT Persons_id, Name FROM Persons WHERE (Active = 1) ORDER BY Name" 
    EnableCaching="True" >
    </asp:SqlDataSource>
   
    <asp:ValidationSummary ID="ValidationSummary3" runat="server" 
        ValidationGroup="input" ShowMessageBox="True" ShowSummary="False" />
   
    <asp:ValidationSummary ID="ValidationSummary2" runat="server" 
        ShowMessageBox="True" ShowSummary="False" ValidationGroup="Insert" />
   
    </form>
</body>
</html>
